<template>
  <div>
    <h1>欢迎访问管理系统</h1>
    <h2>{{time}}</h2>
  </div>
</template>

<script>
  export default {
    name: 'welcome',
    components: {

      // Example
    },
    data () {
      return{
        time:'',
        timer:''
      }
    },

    mounted(){

      if(sessionStorage.getItem('load')){
        sessionStorage.removeItem('load');
        window.location.reload();
      }

      this.time = this.getLocalTime(new Date());
      this.timer = setInterval(() => {
        this.time = this.getLocalTime(new Date());
      },1000)
    },
    beforeRouteLeave (to, from, next) {
      this.$destroy();
      clearInterval(this.timer);
      next();
    },
    methods: {
    getLocalTime(date) {//时间戳转日期
      // const date = new Date(time);
      const year = date.getFullYear()
      const month = date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1
      const day = date.getDate() < 10 ? '0'+date.getDate() : date.getDate()
      const hour = date.getHours() < 10 ? '0'+date.getHours() : date.getHours()
      const minute = date.getMinutes() < 10 ? '0'+date.getMinutes(): date.getMinutes()
      const second = date.getSeconds() < 10 ? '0'+date.getSeconds(): date.getSeconds()
      const t1 = [year, month, day].join('-')
      const t2 = [hour, minute, second].join(':')
      return `${t1} ${t2}`
  },
    }
  }
</script>
<style lang="less" scoped >
  h1,h2{
    text-align: center;
    font-size:50px;
    margin-top:20px;
    font-weight:600
  }
  h2{
    font-size:40px;
  }
</style>
